//
//  CommonViewModel.m
//  Jyxt
//
//  Created by 刘日 on 17/6/1.
//  Copyright © 2017年 DaLian Rental Housing Management. All rights reserved.
//

#import "CommonViewModel.h"
#import "UserCenterViewModel.h"

@implementation CommonViewModel

+ (void)checkResponseBody: (NSDictionary *)response
              whenSuccess: (void (^)())success
                   failed: (void (^)(NSString *reason))failed{
    NSInteger errCode = [response[@"errcode"] integerValue];
    if ([response[@"success"] boolValue]){
        // 成功
        success();
    }
    else if(errCode == 106 || errCode == 107){
        // 需要重新登录
        failed(@"登录异常，请您重新登录");
        [UserCenterViewModel signOut];
    }
    else{
        // 失败
        failed(response[@"errmsg"]);
    }
}

@end
